async function readImagesFromStorage()
{
    // yet to be implemented.
}

async function uploadImage(image)
{
    // yet to be implemented.
}

async function popSelectable(options) {
    // yet to be implemented.
}

async function popConfirmDialog(title, body) {
    // yet to be implemented. should be ez?
}

Component({
    properties: {

    },
    data: {
        images: null
    },
    attached: function () {

    },
    methods: {
        addImage: async function (e) {
            let images = await readImagesFromStorage();
            let imageData = [];
            for (let image of images) {
                imageData.push({
                    url: image.url,
                    done: false
                });
            }
            this.setData({
                images: imageData
            });
            for (let i = 0; i < images.length; i++) {
                let image = images[i];
                await uploadImage(image);
                imageData[i].done = true;
                this.setData({
                    images: imageData
                });
            }
        },

        tapImage: async function (e) {
            let option = await popSelectable([
                '删除',
                '取消'
            ]);
            let index = e.currentTarget.dataset.index;
            if (option == '删除') {
                let choice = await popConfirmDialog('删除图片', '你确定要这么做吗？');
                if (!choice) {
                    return;
                }
                let imageData = this.data.images;
                imageData.splice(index, 1);
                this.setData({
                    images: imageData
                });
            }
        }
    }
})